/**
 * Created by claim on 17-3-12.
 */
let fs = require('fs');
let readPromise = (filename => {
    return new Promise((resolve, reject) => {
        fs.readFile(filename, (err, data) => {
            if (err)
                reject(err);
            resolve(data);
        });
    });
});

readPromise('./1.txt')
    .then(data => {
        console.log(data);
    })
    .then(() => {
        return readPromise('./2.txt');
    })
    .then(data => {
        console.log(data);
    })
    .then(() => {
        return readPromise('./3.txt');
    })
    .then(data => {
        console.log(data);
    })
    .catch(e => {
        console.log(e);
    });

async function readInOrder() {
    let one = await readPromise('./1.txt');
    //one has value
    console.log(one);
    let two = await readPromise('./2.txt');
    console.log(two);
}

readInOrder().catch(e => {
    console.log(e);
});